package wyp.library.ui.activity;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public abstract class WypActivity extends WypLogActivity {

	protected static ArrayList<Activity> ACTIVITY_ARRAY = new ArrayList<Activity>();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.requestWindowFeature(Window.FEATURE_NO_TITLE);
		try {
			ACTIVITY_ARRAY.add(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public View getContentView() {
		ViewGroup _window = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
		return _window.getChildAt(0);
	}

	public boolean isAppInstalled(String __pkgName) {
		PackageInfo __packageInfo = null;
		try {
			__packageInfo = this.getPackageManager().getPackageInfo(__pkgName, 0);
		} catch (NameNotFoundException e) {
			__packageInfo = null;
		}
		if (__packageInfo == null) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public void finish() {
		try {
			ACTIVITY_ARRAY.remove(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.finish();
	}

	public void exitApp() {
		Iterator<Activity> iterator = ACTIVITY_ARRAY.iterator();
		while (iterator.hasNext()) {
			Activity __activity = iterator.next();
			iterator.remove();
			__activity.finish();
		}
	}

}
